﻿using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 人物面板
/// </summary>
public class PropPanel : ShowHideBehaviour {

    public Text Text { get; private set; }
    /// <summary>
    /// 帽子槽
    /// </summary>
    private EquipmentSlot CapSlot;
    /// <summary>
    /// 项链槽
    /// </summary>
    private EquipmentSlot NecklaceSlot;
    /// <summary>
    /// 戒指槽
    /// </summary>
    private EquipmentSlot RingSlot;
    /// <summary>
    /// 武器槽
    /// </summary>
    private EquipmentSlot WeaponSlot;
    /// <summary>
    /// 护甲槽
    /// </summary>
    private EquipmentSlot ArmorSlot;
    /// <summary>
    /// 鞋子槽
    /// </summary>
    private EquipmentSlot ShoesSlot;

	// Use this for initialization
	void Start () {
        base.InitShowHide();
        this.Text = GetComponentInChildren<Text>();
        this.CapSlot = this.transform.Find("CapSlot").GetComponent<EquipmentSlot>();
        this.NecklaceSlot = this.transform.Find("NecklaceSlot").GetComponent<EquipmentSlot>();
        this.RingSlot = this.transform.Find("RingSlot").GetComponent<EquipmentSlot>();
        this.WeaponSlot = this.transform.Find("WeaponSlot").GetComponent<EquipmentSlot>();
        this.ArmorSlot = this.transform.Find("ArmorSlot").GetComponent<EquipmentSlot>();
        this.ShoesSlot = this.transform.Find("ShoesSlot").GetComponent<EquipmentSlot>();
        this.InitEquipments();
        this.UpdateProp();
	}
	
	// Update is called once per frame
	void Update () {
        base.HandleShowHide();
	}

    /// <summary>
    /// 根据类型获得装备槽
    /// </summary>
    /// <param name="articleCategory"></param>
    /// <returns></returns>
    public EquipmentSlot GetEquipmentSlot(Constant.ArticleCategory articleCategory) {
        EquipmentSlot articleSlot = null;
        if (articleCategory == Constant.ArticleCategory.Cap) {
            articleSlot = this.CapSlot;
        } else if (articleCategory == Constant.ArticleCategory.Necklace) {
            articleSlot = this.NecklaceSlot;
        } else if (articleCategory == Constant.ArticleCategory.Ring) {
            articleSlot = this.RingSlot;
        } else if (articleCategory == Constant.ArticleCategory.Weapon) {
            articleSlot = this.WeaponSlot;
        } else if (articleCategory == Constant.ArticleCategory.Armor) {
            articleSlot = this.ArmorSlot;
        } else if (articleCategory == Constant.ArticleCategory.Shoes) {
            articleSlot = this.ShoesSlot;
        }
        return articleSlot;
    }

    public void UpdateProp() {
        GlobalData globalData = GlobalData.Instance;
        Personage personage = globalData.OurTeam[0];
        StringBuilder sb = new StringBuilder();
        sb.Append("姓名：").Append(personage.LastName).Append(personage.FirstName).Append("\n");
        sb.Append("性别：").Append(ObjectHelper.GetDescription(personage.Gender)).Append("\n");
        sb.Append("年龄：").Append(personage.Age).Append("\n");
        sb.Append("等级：").Append(personage.Grade).Append("\n");

        sb.Append("经验：").Append(personage.Exp).Append("/").Append(personage.MaxExp).Append("\n");
        sb.Append("生命：").Append(personage.Hp).Append("/").Append(personage.MaxHp).Append("\n");
        sb.Append("内力：").Append(personage.Mp).Append("/").Append(personage.MaxMp).Append("\n");
        sb.Append("体力：").Append(personage.Vit).Append("/").Append(personage.MaxVit).Append("\n");

        sb.Append("攻击力：").Append(personage.CurrentAttack).Append("\n");
        sb.Append("防御力：").Append(personage.CurrentDefense).Append("\n");
        sb.Append("拳掌：").Append(personage.CurrentFist).Append("\n");
        sb.Append("腿法：").Append(personage.CurrentLeg).Append("\n");
        sb.Append("剑法：").Append(personage.CurrentSword).Append("\n");
        sb.Append("刀法：").Append(personage.CurrentKnife).Append("\n");
        sb.Append("棍法：").Append(personage.CurrentStick).Append("\n");
        sb.Append("医术：").Append(personage.CurrentLeechcraft).Append("\n");
        sb.Append("毒术：").Append(personage.CurrentPoison).Append("\n");
        sb.Append("力量：").Append(personage.CurrentPower).Append("\n");
        sb.Append("身法：").Append(personage.CurrentSpeed).Append("\n");
        sb.Append("根骨：").Append(personage.CurrentPhysique).Append("\n");
        sb.Append("悟性：").Append(personage.CurrentSavvy).Append("\n");
        sb.Append("坚韧：").Append(personage.CurrentTenacity).Append("\n");

        sb.Append("样貌：").Append(personage.Appearance).Append("\n");
        sb.Append("道德：").Append(personage.Morality).Append("\n");

        this.Text.text = sb.ToString();
    }

    private void InitEquipments() {
        Personage personage = GlobalData.Instance.GetPlayerPersonage();
        Dictionary<Constant.ArticleCategory, Article> equipArticles = personage.EquipArticles;
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Cap) && this.CapSlot.IsEmpty()) {
            this.CapSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Cap]);
        }
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Necklace) && this.NecklaceSlot.IsEmpty()) {
            this.NecklaceSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Necklace]);
        }
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Ring) && this.RingSlot.IsEmpty()) {
            this.RingSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Ring]);
        }
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Weapon) && this.WeaponSlot.IsEmpty()) {
            this.WeaponSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Weapon]);
        }
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Armor) && this.ArmorSlot.IsEmpty()) {
            this.ArmorSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Armor]);
        }
        if (equipArticles.ContainsKey(Constant.ArticleCategory.Shoes) && this.ShoesSlot.IsEmpty()) {
            this.ShoesSlot.StoreArticle(equipArticles[Constant.ArticleCategory.Shoes]);
        }
    }
}
